﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VFDDriver.Properties;
using System.Timers;


namespace VFDDriver
{
    public class Data
    {
        #region Properties

        List<DisplayLineData> _lines;

        #region SyncRoot

        private object _syncRoot;
        /// <summary>TODO: Add description here.</summary>
        public object SyncRoot
        {
            get
            {
                if (_syncRoot == null)
                    _syncRoot = new object();
                return _syncRoot;
            }
        }

        #endregion

        #region Instance

        static Data _instance;

        /// <summary>
        /// Instance of the Data.
        /// </summary>
        public static Data Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Data();
                return _instance;
            }
        }

        #endregion

        #endregion

        #region Constructors

        private Data()
        {
            _lines = new List<DisplayLineData>();
            for (int i = 0; i < Settings.Default.VFD_NrLines; i++)
            {
                _lines.Add(new DisplayLineData(string.Empty, Alignment.Left));
            }
        }

        #endregion

        #region Methods

        #endregion

        public void SetData(int line, string value, Alignment align)
        {
            lock (SyncRoot)
            {
                if (_lines[line - 1].CurrentValue != value || _lines[line - 1].Align != align)
                    _lines[line - 1] = new DisplayLineData(value, align);
            }

        }

        public string GetData(int line)
        {
            lock (SyncRoot)
            {
                return _lines[line - 1].DisplayValue;
            }
        }
    }
}
